﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Add.aspx.cs" Inherits="fsw.Web.Manager.Add" ValidateRequest="false" %>

<%@ Register Src="~/HeaderJs.ascx" TagPrefix="uc1" TagName="HeaderJs" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="renderer" content="webkit" />
    <title>添加管理员</title>
    <uc1:HeaderJs runat="server" ID="HeaderJs" />
</head>
<body>
    <div class="position">当前位置：管理员管理  > <a href="List.aspx">管理员列表</a></div>
    <div class="border">
        <legend>添加管理员</legend>
        <form id="form1" class="am-form am-form-horizontal" runat="server">
            <div class="am-form-group">
                <label class="am-u-sm-2 am-form-label">用户名</label>
                <div class="am-u-sm-10">
                    <input type="text" name="UserName" size="30" maxlength="20" placeholder="请输入用户名" data-rule="用户名:required;username" />
                </div>
            </div>
            <div class="am-form-group">
                <label class="am-u-sm-2 am-form-label">密码</label>
                <div class="am-u-sm-10">
                    <input type="text" name="PassWord" size="30" maxlength="16" placeholder="请输入密码" data-rule="密码:required;password;" />
                </div>
            </div>
            <div class="am-form-group">
                <label class="am-u-sm-2 am-form-label">中文名</label>
                <div class="am-u-sm-10">
                    <input type="text" name="RealName" size="30" placeholder="请输入中文名" data-rule="中文名:required;" />
                </div>
            </div>
            <div class="am-form-group">
                <label class="am-u-sm-2 am-form-label">管理员级别</label>
                <div class="am-u-sm-10">
                    <select name="TypeId">
                        <option value="2">普通管理员</option>
                        <option value="1">超级管理员</option>
                    </select>
                </div>
            </div>             
            <div class="am-form-group am-form-data">
                <label class="am-u-sm-2 am-form-label">所属项目</label>
                <div class="am-u-sm-10">
                     <%foreach (fsw.Model.Project m in ListProject) { 
                      %>
                      <div class="userposs"><input type="checkbox" value="<%=m.Id %>" id="admin_<%=m.Id %>" name="UserProject"/> <label for="admin_<%=m.Id %>"><%=m.HosName %></label></div>
                      <%} %>                    
                </div>              
            </div>
            <div class="am-form-group am-form-data">
                <label class="am-u-sm-2 am-form-label">所属模块</label>
                <div class="am-u-sm-10">
                   <% foreach (fsw.Model.Mould m in ListMould)
                      {%>
                      <div class="userposs"><input type="checkbox" value="<%=m.Id %>" id="UserModule_<%=m.Id %>" name="UserModule" /><label for="UserModule_<%=m.Id %>"><%=m.MouldName %></label></div>
                   <%} %> 
                </div>
            </div>
            <div class="am-form-group">
                <label class="am-u-sm-2 am-form-label">是否启用</label>
                <div class="am-u-sm-10">
                    <div class="rule-single-checkbox">
                        <input type="checkbox" name="isStatus" checked="checked" />
                    </div>
                    <span class="am-margin-left input-tips"></span>
                </div>
            </div>
            <div class="am-form-group">
                <div class="am-u-sm-10 am-u-sm-offset-2">
                    <button type="submit" class="am-btn am-btn-primary am-radius">保存</button>
                    <button type="button" class="am-btn am-radius am-back">返回</button>
                </div>
            </div>
        </form>
    </div>
    <script>
        $(function () {
            $('select[name=TypeId]').on('change', function () {
                if ($(this).val() == 1) {
                    $('.am-form-data').hide();
                } else {
                    $('.am-form-data').show();
                }
            })
            toastr.options = { "positionClass": "toast-bottom-center", "timeOut": "3000", "onclick": null, showMethod: "slideDown", hideMethod: "slideUp" };
            $('.am-form').validator({
                timely: 2,
                stopOnError: true,
                focusCleanup: true,
                ignore: ':hidden',
                theme: 'yellow_right_effect',
                valid: function (form) {
                    $.AMUI.progress.inc();
                    $.ajax({
                        type: 'post',
                        cache: false,
                        dataType: 'json',
                        url: 'Add.aspx',
                        data: $(form).serialize(),
                        error: function (e) { alert(e.responseText); },
                        success: function (d) {
                            $.AMUI.progress.set(1.0);
                            if (d.state == 'success') {
                                toastr.success(d.msg);
                                setTimeout(function () { location.href = 'List.aspx'; }, 1500);
                            }
                            else {
                                toastr.error(d.msg);
                            }

                        }
                    })
                }
            });
        })
    </script>
</body>
</html>
